/**
 * 检查是否登录
 */
let mno;
$(function(){
	//直接发送ajax请求，验证一下session里面有没有存值
	$.post("member",{
		op: 'checkLogin'
	},function(data){
		let str = '';
		if( data == 0 ){
			if( location.pathname == "/snacknet/order.html" || location.pathname ==  "/snacknet/pay.html"){
				location.href = "login.html";
			}
			str +='<a href="login.html" title="点击登录">您好，请登录</a><a href="register.html" title="点击注册"> 免费注册 </a>';
		}else{
			str += '<a href="javascript:void(0)">欢迎您：['+data.nickName+']</a>';
			str +='<a href="login.html" >退出登录</a>';
				
			//查找购物车，登录成功的时候，才查找购物车
			mno = data.mno; 
			console.log()
			getCartInfo(mno);
		}
		$(".login-info").html(str);
	},"json");
	
	
	//还要获取到菜单
	$.post("member",{
		op: 'getAllTypes'
	},function(data){
		let str = '<a href="javascript:void(0)" class="selected" data-id=""  onclick="findByTno(this,0)">全部</a>';
		for(  i = 0; i < data.length; i++ ){
			str += '<a href="javascript:void(0)"  data-id="'+data[i].tno+'" onclick="findByTno(this,'+data[i].tno+')">'+data[i].tname+'</a>';
		}
		$("#search_item").html(str);
	},"json");
})


//得到购物车里面的数据
var carts = [];
function getCartInfo(mno){
	$.post("cart",{
		op: 'getCart',
		mno: mno
	},function(data){
		if(data == null || data.length <= 0){
			return;
		}
		carts = data;
		$(".iconfont").html( data.length );
	},"json")
}


